Sanitize sensitive variables in RequestPanel #2105
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request enhances the
debug_toolbar
package by adding functionality to sanitize sensitive data in the Request Panel. It includes changes to theRequestPanel
class, utility functions, and tests to ensure sensitive data is properly redacted.Sanitization of sensitive data:
debug_toolbar/panels/request.py
: Updated thegenerate_stats
method to usesanitize_and_sort_request_vars
for GET, POST, cookies, and session data. [1] [2]debug_toolbar/utils.py
: Introduced thesanitize_and_sort_request_vars
function to replaceget_sorted_request_variable
, ensuring sensitive values are redacted. Added helper functions_get_sorted_keys
,_process_query_dict
, and_process_dict
to support sanitization as part of refactoring effort. [1] [2]Testing enhancements:
tests/panels/test_request.py
: Added multiple tests to verify that sensitive data in POST, GET, cookies, and session data is redacted.tests/test_utils.py
: Added a new test case classSanitizeAndSortRequestVarsTestCase
to test the sanitization functionality for different input types.Documentation update:
docs/changes.rst
: Documented the new feature to sanitize sensitive data in the Request Panel.Fixes #2074
Checklist:
docs/changes.rst
.